package com.cb.kfc.service.impl;

import com.cb.kfc.dao.IMemberDao;
import com.cb.kfc.domain.Member;
import com.cb.kfc.service.IMemberService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class MemberServiceImpl implements IMemberService {
    @Autowired
    private IMemberDao memberDao ;
    @Override
    public List<Member> findAll(int page, int size) throws Exception {
        //        加入pagehelper插件,pageNum是页码值，pageSize是每页显示条数
        PageHelper.startPage(page,size);
        return memberDao.findAll();
    }

    @Override
    public void save(Member member) {
        memberDao.save(member);
    }

    @Override
    public Integer deleteProductById(String[] ids) {
        Integer i =memberDao.delete(ids);
        return i;
    }

    @Override
    public Member findById(String id) {
        return memberDao.findById(id);
    }

    @Override
    public void give(String orderid, String friendid) {
        memberDao.give(orderid,friendid);
    }

    /**
     * 获得用户的id，批量，或者单个删除角色
     */
    public Integer deleteFriend(String[] ids) {
        if(ids !=null && ids.length>0){
            Integer integer = memberDao.deleteFriend(ids);
            return integer;
        }
        return 0;
    }

    @Override
    public void update(Member member) {
        memberDao.update(member);
    }
}
